package com.tuyenmonkey.mkloader.type;

import com.tuyenmonkey.mkloader.callback.InvalidateListener;
import ohos.agp.components.element.Element;
import ohos.agp.render.Canvas;
import ohos.agp.utils.Color;
import ohos.agp.utils.Point;

/**
 * Created by Tuyen Nguyen on 2/11/17.
 */

public abstract class LoaderView{
  protected Color color;
  protected int width, height;
  protected int desiredWidth, desiredHeight;
  protected Point center;
  protected InvalidateListener invalidateListener;

  public LoaderView() {
    this.desiredWidth = 150;
    this.desiredHeight = 150;
  }

  public void setColor(Color color) {
    this.color = color;
  }


  public void setSize() {
    this.width = desiredWidth;
    this.height = desiredHeight;
    this.center = new Point(desiredWidth / 2.0f, desiredHeight / 2.0f);
  }

  public void setInvalidateListener(InvalidateListener invalidateListener) {
    this.invalidateListener = invalidateListener;
  }

  public int getDesiredWidth() {
    return desiredWidth;
  }

  public int getDesiredHeight() {
    return desiredHeight;
  }

  public abstract void initializeObjects();

  public abstract void setUpAnimation();

  public abstract void draw(Canvas canvas);

  public boolean isDetached() {
    return invalidateListener == null;
  }

  public void onDetach() {
    if (invalidateListener != null) {
      invalidateListener = null;
    }
  }

}
